;
upload={
    error:function(msg){
        alert(msg);
    },
    success:function(image_key){
        var html='<img src="'+common_ops.buildPicUrl('brand',image_key)+'"><span class="fa fa-times-circle del del_image" data="'+image_key+'"><i></i></span>';
        if($(".upload_pic_wrap .pic-each").size()>0){
            $(".upload_pic_wrap .pic-each").html(html);
        }else{
            $(".upload_pic_wrap").append('<span class="pic-each">'+html+'</span>');
        }

        //为新上传的图片绑定删除图片效果
        brand_set_ops.delete_image();
    }

};

var brand_set_ops={
    init:function(){
        this.eventBind();
        this.delete_image();
    },

    eventBind:function(){
        $(".wrap_brand_set .save").click(function(){
           var btn_target=$(this);
           if(btn_target.hasClass("disabled")){
               alert("正在处理,请不要多次提交~~");
               return;
           }

           var image_key=$(".wrap_brand_set .pic-each .del_image").attr("data");

           var name_target=$(".wrap_brand_set input[name=name]");
           var name=name_target.val();

           var mobile_target=$(".wrap_brand_set input[name=mobile]");
           var mobile=mobile_target.val();

           var address_target=$(".wrap_brand_set input[name=address]");
           var address=address_target.val();

            var description_target=$(".wrap_brand_set textarea[name=description]");
            var description=description_target.val();

            if($(".upload_pic_wrap .pic-each").size()<1){
                alert("请上传logo图片");
                return ;
            }

            if(name.length<1){
                common_ops.tip("请输入品牌名称~~",name_target);
                return;
            }

            if(mobile.length<1){
                common_ops.tip("请输入电话~~",mobile_target);
                return;
            }

            if(address.length<1){
                common_ops.tip("请输入地址名称~~",address_target);
                return;
            }

            if(description.length<1){
                common_ops.tip("请输入描述信息~~",description_target);
                return;
            }

            btn_target.addClass("disabled");

            var data={
                name:name,
                mobile:mobile,
                address:address,
                description:description,
                image_key:image_key
            };
            $.ajax({
                url:common_ops.buildWebUrl('/brand/set'),
                type:'POST',
                data:data,
                dataType:'json',
                success:function(res){
                    btn_target.removeClass("disabled");
                    var callback=null;
                    if(res.code==200){
                        callback=function(){
                            window.location.href=common_ops.buildWebUrl('/brand/info');
                        }
                    }
                    common_ops.alert(res.msg,callback);
                }
            });
        });

        $(".wrap_brand_set .upload_pic_wrap input[name=pic]").change(function(){
            $(".wrap_brand_set .upload_pic_wrap").submit();
        });
    },
    delete_image:function(){
        $(".wrap_brand_set .del_image").unbind().click(function(){
            $(this).parent().remove();
        });
    }
};

$(document).ready(function(){
   brand_set_ops.init();
});